package com.freight.order.controller;

import com.freight.core.base.FreightBaseController;
import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.core.common.vo.SearchVo;
import com.freight.order.entity.OrderTrack;
import com.freight.order.service.OrderTrackService;
import com.freight.order.vo.MobileTrackVo;
import com.freight.order.vo.OrderTrackVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "订单行车路径管理接口")
@RequestMapping("/freight/orderTrack")
@Transactional
public class OrderTrackController extends FreightBaseController<OrderTrack, Long> {

    @Autowired
    private OrderTrackService orderTrackService;

    @Override
    public OrderTrackService getService() {
        return orderTrackService;
    }


    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "多条件分页获取")
    public Result<Page<OrderTrack>> getByCondition(OrderTrack orderTrack, SearchVo searchVo, PageVo pageVo) {

        Page<OrderTrack> page = orderTrackService.findByCondition(orderTrack, searchVo, PageUtil.initPage(pageVo));
        return new ResultUtil<Page<OrderTrack>>().setData(page);
    }

    @RequestMapping(value = "/getMobileTrack", method = RequestMethod.GET)
    @ApiOperation(value = "获取订单手机轨迹")
    public Result<List<MobileTrackVo>> getMobileTrack(Long orderId){
        System.out.println(orderId);
        List<MobileTrackVo> mobileTracks = orderTrackService.getMobileTrack(orderId);
        return  new ResultUtil<List<MobileTrackVo>>().setData(mobileTracks);
    }

    @RequestMapping(value = "/updateMobileTrack", method = RequestMethod.GET)
    @ApiOperation(value = "矫正轨迹")
    public Result<List<MobileTrackVo>> updateMobileTrack(){
        orderTrackService.updateMobileTrack();
        return  new ResultUtil<List<MobileTrackVo>>().setData(null);
    }

    @RequestMapping(value = "/getTracks", method = RequestMethod.GET)
    @ApiOperation(value = "获取订单车辆轨迹")
    public Result<List<OrderTrackVo>> getTracks(Long orderId){
        System.out.println(orderId);

        List<OrderTrackVo> orderTrackVos = orderTrackService.getTracks(orderId);

        return  new ResultUtil<List<OrderTrackVo>>().setData(orderTrackVos);
    }

    @RequestMapping(value = "/getHistoryTracks", method = RequestMethod.POST)
    @ApiOperation(value = "获取车辆历史轨迹")
    public Result<List<OrderTrackVo>> getHistoryTracks(String gpsEquipment, String startTime, String endTime){

        List<OrderTrackVo> orderTrackVos = orderTrackService.getHistoryTracks(gpsEquipment, startTime, endTime);

        return  new ResultUtil<List<OrderTrackVo>>().setData(orderTrackVos);
    }


}
